package com.credit.mola.app.weight.font;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.credit.mola.app.R;

/**
 * Sikadwa
 *
 * @Author wwdeng
 * @CreateTime: 2024/12/26 21:34
 * @Annotation：
 */
public class NormalTextViewDel extends AppCompatTextView {

    private boolean flag = true;

    public NormalTextViewDel(Context context) {
        super(context);
    }
    public NormalTextViewDel(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public NormalTextViewDel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    public void setTypeface(@Nullable Typeface tf) {
        super.setTypeface(tf);
    }
    @Override
    public void setTypeface(@Nullable Typeface tf, int style) {
        super.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    }

    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (flag) {
            @SuppressLint("DrawAllocation") Paint paint = new Paint();
            // 设置直线的颜色
            paint.setColor(getResources().getColor(R.color.FFFF451F));
            // 设置直线没有锯齿
            paint.setAntiAlias(true);
            // 设置线宽
            paint.setStrokeWidth(4f);
            // 设置直线位置
            canvas.drawLine(getPaddingStart(), (float) this.getHeight() / 2, this.getWidth(), (float) this.getHeight() / 2, paint);
        }
    }

    /**
     * true显示删除线     false不显示删除线
     * @param flag
     * @return flag
     */

    public boolean setTv(boolean flag) {
        this.flag = flag;
        return flag;
    }
}
